package edu.ihs.lhpy.domain;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

public class User implements Serializable{
	private Long id;
	private String name;
	private String realName;
	private String password;
	private Set<Privilege> privileges = new HashSet<Privilege>(); // 所拥有的权限
	
	
	/**
	 * 判断本用户是否有指定名称的权限
	 * 
	 * @param privilegeName
	 * @return
	 */
	public boolean hasPrivilegeByName(String privilegeName) {
		// 超级管理员有所有的权限
		if (isAdmin()) {
			return true;
		}
		//TODO 菜单栏依据权限显示
		//其他用户要是有权限才返回true
//		System.out.println(user.getName());
//		for (Privilege privilege : user.getPrivileges()) {
//			if (privilege.getName().equals(privilegeName)) {
//				return true;
//			}
//		}
			return false;
		}
	
	/**
	 * 是否是超级管理员
	 * 
	 * @return
	 */
	public boolean isAdmin() {
//		System.out.println(name);
		return "admin".equals(name);
	}
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public Set<Privilege> getPrivileges() {
		return privileges;
	}
	public void setPrivileges(Set<Privilege> privileges) {
		this.privileges = privileges;
	}
	public String getRealName() {
		return realName;
	}
	public void setRealName(String realName) {
		this.realName = realName;
	}

	public boolean hasPrivilegeByUrl(String url) {
		return true;
	}
	
	
	
}
